{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "30a4de4a",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "* 元组，集合、字典的基本概念和常见方法\n",
    "> 1. 元组\n",
    "> 2. 集合\n",
    "> 3. 字典"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44287286",
   "metadata": {},
   "source": [
    "## 1.元组（tuple）\n",
    "> 1. 概念\n",
    ">> 1. 具有和序列数据相同的运算规则：取值和切片\n",
    ">> 2. 表征：（12345，54321，‘hello’），用圆括号/小括号括起来的，中间仍是用逗号隔开的数据形态\n",
    "> 2. 性质不可变,没有什么增删改的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "26c26d1e",
   "metadata": {},
   "outputs": [],
   "source": [
    "product=(\"head first python\",88)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "191d71e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('head first python', 88) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "print(product,type(product))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "17dd5e3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 案例：\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "851accf2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=10, tm_mday=31, tm_hour=10, tm_min=19, tm_sec=55, tm_wday=0, tm_yday=304, tm_isdst=0)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "72497988",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on struct_time object:\n",
      "\n",
      "class struct_time(builtins.tuple)\n",
      " |  struct_time(iterable=(), /)\n",
      " |  \n",
      " |  The time value as returned by gmtime(), localtime(), and strptime(), and\n",
      " |  accepted by asctime(), mktime() and strftime().  May be considered as a\n",
      " |  sequence of 9 integers.\n",
      " |  \n",
      " |  Note that several fields' values are not the same as those defined by\n",
      " |  the C language standard for struct tm.  For example, the value of the\n",
      " |  field tm_year is the actual year, not year - 1900.  See individual\n",
      " |  fields' descriptions for details.\n",
      " |  \n",
      " |  Method resolution order:\n",
      " |      struct_time\n",
      " |      builtins.tuple\n",
      " |      builtins.object\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __reduce__(...)\n",
      " |      Helper for pickle.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  tm_gmtoff\n",
      " |      offset from UTC in seconds\n",
      " |  \n",
      " |  tm_hour\n",
      " |      hours, range [0, 23]\n",
      " |  \n",
      " |  tm_isdst\n",
      " |      1 if summer time is in effect, 0 if not, and -1 if unknown\n",
      " |  \n",
      " |  tm_mday\n",
      " |      day of month, range [1, 31]\n",
      " |  \n",
      " |  tm_min\n",
      " |      minutes, range [0, 59]\n",
      " |  \n",
      " |  tm_mon\n",
      " |      month of year, range [1, 12]\n",
      " |  \n",
      " |  tm_sec\n",
      " |      seconds, range [0, 61])\n",
      " |  \n",
      " |  tm_wday\n",
      " |      day of week, range [0, 6], Monday is 0\n",
      " |  \n",
      " |  tm_yday\n",
      " |      day of year, range [1, 366]\n",
      " |  \n",
      " |  tm_year\n",
      " |      year, for example, 1993\n",
      " |  \n",
      " |  tm_zone\n",
      " |      abbreviation of timezone name\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  n_fields = 11\n",
      " |  \n",
      " |  n_sequence_fields = 9\n",
      " |  \n",
      " |  n_unnamed_fields = 0\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Methods inherited from builtins.tuple:\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(self, key, /)\n",
      " |      Return self[key].\n",
      " |  \n",
      " |  __getnewargs__(self, /)\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __hash__(self, /)\n",
      " |      Return hash(self).\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  count(self, value, /)\n",
      " |      Return number of occurrences of value.\n",
      " |  \n",
      " |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      " |      Return first index of value.\n",
      " |      \n",
      " |      Raises ValueError if the value is not present.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Class methods inherited from builtins.tuple:\n",
      " |  \n",
      " |  __class_getitem__(...) from builtins.type\n",
      " |      See PEP 585\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "61567dbf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1800001, 1800002, 1800003)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_seq =1800001,1800002,1800003\n",
    "name_seq"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e98b8a5",
   "metadata": {},
   "source": [
    "## 2.集合（Sets）\n",
    "> 1.集合的概念\n",
    ">> 1. 没有重复元素的一个数据结构\n",
    ">> 2. 形态：{'apple','orrange','apple','pear','orrange','banana'}\n",
    "> 2. 集合的运算\n",
    ">> 1. 交集的运算：   &    ，intersection\n",
    ">> 2. 并集运算：    |    ， union"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "68c66518",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'orrange', 'pear', 'apple', 'banana'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "basket={'apple','orrange','apple','pear','orrange','banana'}\n",
    "print(basket,type(basket))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a04b7820",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社={18001,18003,18004,18005,18007}\n",
    "合唱团={18009,18111,18004,18001}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b984974e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "074fee55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(合唱团)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1a22edde",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{18001, 18004}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社 & 合唱团"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c34236ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{18001, 18004}\n",
      "{18001, 18004}\n"
     ]
    }
   ],
   "source": [
    "# 交集\n",
    "print(舞蹈社 & 合唱团)\n",
    "print(舞蹈社.intersection(合唱团))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ab1e2a4f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{18001, 18003, 18004, 18005, 18007, 18009, 18111}\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "# 并集\n",
    "print(舞蹈社 | 合唱团)\n",
    "print(len(舞蹈社 | 合唱团))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae08171a",
   "metadata": {},
   "source": [
    "# 3. 字典（dict）\n",
    "> 1. 基本的概念\n",
    ">> 1. mapping types:映射类型\n",
    ">> 2. key:vaules,键，值，对\n",
    ">> 3. 字典的性质\n",
    ">>> 1. 无序性\n",
    ">>> 2. key不可变性\n",
    ">>> 3. key唯一性\n",
    "> 2. 字典的创建\n",
    "> 3. 常用的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "56c4ad24",
   "metadata": {},
   "outputs": [],
   "source": [
    "product_dict={\n",
    "    \"apple\":6,\n",
    "    \"pear\":10,\n",
    "    \"banana\":12,\n",
    "    \"bobo\":8,\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "9db84e06",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'apple': 6, 'pear': 10, 'banana': 12, 'bobo': 8} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(product_dict,type(product_dict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f92b2ac2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "product_dict[\"apple\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "135dd438",
   "metadata": {},
   "outputs": [],
   "source": [
    "user_info={\n",
    "    \"bbi1122\":[\"zhichao\",\"it\",\"广州\",\"广州南方学院\"]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "cfb4a1f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['zhichao', 'it', '广州', '广州南方学院']"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info[\"bbi1122\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d15291e9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
